package cn.com.bsoft.kotlinEx

import com.google.common.base.CaseFormat
import org.apache.commons.text.CharacterPredicate
import org.apache.commons.text.RandomStringGenerator

fun randomString(length: Int, accept: String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%&*()-=+{}[]/<>?"): String {
    val generator = RandomStringGenerator.Builder().filteredBy(
            CharacterPredicate { c ->
                if (c > Char.MAX_SURROGATE.toInt()) false
                else
                    accept.contains(c.toChar())
            }
    ).build()

    return generator.generate(length)
}

val String.lowerUnderScore:String get() {
    return CaseFormat.UPPER_CAMEL.to(
            CaseFormat.LOWER_UNDERSCORE,this
    )
}

val String.upperCamel:String get() {
    return CaseFormat.LOWER_UNDERSCORE.to(
            CaseFormat.UPPER_CAMEL,this
    )
}